<%# locals: sel_year, sel_month, sel_day, item_count, action -%>
<% selected_month = Date.new(sel_year.to_i, sel_month.to_i, 1) -%>
<% prev_month = selected_month << 1 -%>
<% next_month = selected_month >> 1 -%>
<% now_month = Date.today -%>
<% action ||= 'index' -%>
<div class="box_space" id="calendar_body">
  <div class="box_space_body">
    <%= calendar(:year => sel_year, :month => sel_month) do |day|
          if item_count == nil or item_count[day.mday]
            cell_text = link_to(day.mday, :action => action, :year => sel_year, :month => sel_month, :day => day.mday)
          else
            cell_text = day.mday
          end

          if day == Date.today
            cell_attrs = { :class => 'today' }
          elsif sel_day && day == Date.new(sel_year, sel_month, sel_day)
            cell_attrs = { :class => 'selected' }
          elsif day.wday == 0 or day.wday == 6 or HOLIDAYS[day]
            cell_attrs = { :class => 'holiday' }
          else
            cell_attrs = { :class => 'day' }
          end
          [cell_text, cell_attrs]
        end
    -%>
  </div>
  <div class="box_space_bottom">
    <a id="prev_month_link" href="#" >[前月]</a>
    <%= link_to('[今日]', {:action => action, :year => now_month.year, :month => now_month.month, :day => now_month.day}) %>
    <a id="next_month_link" href="#" >[次月]</a>
  </div>
</div><!-- box_space -->

<script language="JavaScript" type="text/javascript">
$j(function(){
    var loadCalendar = function(year, month){
        $j.ajax({
            url: '<%= url_for( :action => 'load_calendar') -%>',
            data: { year : year , month : month },
            complete: function(request) {
               $j('#calendar')
               .html(request.responseText);
               $j('#calendar_body')
               .highlight();
            }
        });
    };

    // カレンダーの前月、次月リンククリック時のajaxアクション
    $j('#prev_month_link')
    .click(function() {
        loadCalendar(<%= prev_month.year -%>, <%= prev_month.month -%>);
        return false;
    });

    $j('#next_month_link')
    .click(function() {
        loadCalendar(<%= next_month.year -%>, <%= next_month.month -%>);
        return false;
    });
}); // $j(function(){
</script>
